# -*- coding: utf-8 -*-
import os

import cv2
import tms.util.location as location
import jd.action as action

scene_list = [
    'page_moniqi_index.png',
    'page_index.png',
    'page_list.png',
    'page_address.png',
    'page_cart.png',
    'page_add_address.png',
    'page_select_city.png',
    'page_select_area.png',
    'page_search.png',
]

scene_path = '/sam/img/scene/'

# 获取场景
def getscene(route):
    cut_main_gray = action.get_main_gray()
    for scene in scene_list:
        scene_gray = cv2.cvtColor(cv2.imread(os.getcwd() + scene_path + scene), cv2.COLOR_BGR2GRAY)
        locations = location.getlocations(cut_main_gray, scene_gray)

        if len(locations) > 0:
            page = None
            if 'page_moniqi_index' in scene:
                page = "模拟器"
            elif 'page_index' in scene:
                page = "首页"
            elif 'page_search' in scene:
                page = "搜索"
            elif 'page_list' in scene:
                page = "商品列表"
            elif 'page_cart' in scene:
                page = "购物车"
            elif 'page_address' in scene:
                page = "收货地址"
            elif 'page_add_address' in scene:
                page = "新增收货地址"
            elif 'page_select_area' in scene:
                page = "所在地区"
            elif 'page_select_city' in scene:
                page = "选择城市"

            if page is not None:
                if (route[0] == '' or page != route[1]):
                    route[0] = route[1]
                    route[1] = page
                print('当前场景为: ', page)
                print('路由: ', route)
                return page
    return "未知"